package org.dizena.utils;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil<V>
{
    @Resource
    private RedisTemplate<String, V> redisTemplate;

    public void add(String key, V v, long second)
    {
        redisTemplate.boundValueOps(key).set(v, second, TimeUnit.SECONDS);
    }

    public V get(String key)
    {
        return redisTemplate.boundValueOps(key).get();
    }

    public boolean delete(String key)
    {
        return Boolean.TRUE.equals(redisTemplate.delete(key));
    }

}
